package com.imau.config;

import com.imau.common.interceptor.ProjectInterceptor;
import com.imau.common.interceptor.ProjectInterceptor2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class SpringMvcSuppot extends WebMvcConfigurationSupport {

    @Autowired
    private ProjectInterceptor interceptor;
    @Autowired
    private ProjectInterceptor2 interceptor2;
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {


        registry.addInterceptor(interceptor).addPathPatterns("/books").addPathPatterns("/books/*");
        registry.addInterceptor(interceptor2).addPathPatterns("/books").addPathPatterns("/books/*");
    }
}

